package com.SMP.controller.class_room;

import com.SMP.model.Gradeclass;
import com.SMP.model.Msg;
import com.SMP.service.class_room.GradeClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class GradeClassController {

    @Autowired
    GradeClassService gradeClassService;

    /**
     * 增加班级
     * @author WYHY
     * @param gradeclass 班级
     *
     * */
    @RequestMapping("/addGC")
    @ResponseBody
    public Msg addGC(Gradeclass gradeclass){
        int result=0;
        result=gradeClassService.addGC(gradeclass);
        if (result==0){
            return Msg.fail();
        }else{
            return Msg.success();
        }
    }

    /**
     * 删除年级
     * @author WYHY
     * @param grade 年级
     *
     * */
    @RequestMapping("/delG")
    @ResponseBody
    public Msg delG(String grade){
        int result=0;
        result=gradeClassService.delG(grade);
        if (result==0){
            return Msg.fail();
        }else{
            return Msg.success();
        }
    }

    /**
     * 删除班级
     * @author WYHY
     * @param id 班级
     *
     * */
    @RequestMapping("/delC")
    @ResponseBody
    public Msg delC(String id){
        int result=0;
        result=gradeClassService.delC(id);
        if (result==0){
            return Msg.fail();
        }else{
            return Msg.success();
        }
    }

    /**
     * 年级查询
     * @author WYHY
     *
     * */
    @RequestMapping("/selG")
    @ResponseBody
    public Msg selGrade(){
        List result=gradeClassService.selGrade();
        if (result==null){
            return Msg.fail();
        }else{
            return Msg.success().add("grade",result);
        }
    }

    /**
     * 查询班级
     * @author WYHY
     *
     * */
    @RequestMapping("/selC")
    @ResponseBody
    public Msg selectClasss(String grade){
        List result=gradeClassService.selClass(grade);
        if (result==null){
            return Msg.fail();
        }else{
            return Msg.success().add("classs",result);
        }
    }
}
